home *** CD-ROM | disk | FTP | other *** search
/ GFX Sensations 1 / Graphic Sensations - Volume 1.iso / tools / amiga / 3d_tools / irit40s.lha / Irit / grapdrvs / drawln3d.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-30  |  2.6 KB  |  98 lines

  1. /*****************************************************************************
  2. *   Default 3d line drawing routine common to graphics drivers.             *
  3. *                                         *
  4. * Written by:  Gershon Elber                Ver 0.1, June 1993.  *
  5. *****************************************************************************/
  6.  
  7. #include "irit_sm.h"
  8. #include "genmat.h"
  9. #include "iritgrap.h"
  10.  
  11. static RealType CurrentPos[3];
  12.  
  13. /****************************************************************************
  14. * Routine to move in 3D object space.                        *
  15. ****************************************************************************/
  16. void IGMoveTo3D(RealType *Pt)
  17. {
  18.     MatMultVecby4by4(CurrentPos, Pt, IGGlblCrntViewMat);
  19.     IGMoveTo2D(CurrentPos[0], CurrentPos[1]);
  20. }
  21.  
  22. /****************************************************************************
  23. * Routine to draw in 3D object space.                        *
  24. ****************************************************************************/
  25. void IGLineTo3D(RealType *Pt)
  26. {
  27.     RealType NewPos[3];
  28.  
  29.     MatMultVecby4by4(NewPos, Pt, IGGlblCrntViewMat);
  30.  
  31.     if (IGGlblDepthCue) {
  32.     if (CurrentPos[2] <= 0.0 && NewPos[2] <= 0.0) {
  33.         if (IGGlblIntensityHighState)
  34.         IGSetColorIntensity(FALSE);
  35.  
  36.         IGLineTo2D(NewPos[0], NewPos[1]);
  37.     }
  38.     else if ((CurrentPos[2] >= 0.0 && NewPos[2] >= 0.0) ||
  39.          ABS(CurrentPos[2] - NewPos[2]) < EPSILON) {
  40.         if (!IGGlblIntensityHighState)
  41.         IGSetColorIntensity(TRUE);
  42.  
  43.         IGLineTo2D(NewPos[0], NewPos[1]);
  44.     }
  45.     else {                      /* Line intersect Z = 0 plane. */
  46.         RealType MidPos[3],
  47.         t = CurrentPos[2] / (CurrentPos[2] - NewPos[2]);
  48.  
  49.         MidPos[0] = CurrentPos[0] * (1.0 - t) + NewPos[0] * t;
  50.         MidPos[1] = CurrentPos[1] * (1.0 - t) + NewPos[1] * t;
  51.  
  52.         if (IGGlblIntensityHighState) {
  53.         if (CurrentPos[2] > 0.0) {
  54.             IGLineTo2D(MidPos[0], MidPos[1]);
  55.         }
  56.         else {
  57.             IGLineTo2D(NewPos[0], NewPos[1]);
  58.             IGMoveTo2D(MidPos[0], MidPos[1]);
  59.         }
  60.  
  61.         IGSetColorIntensity(FALSE);
  62.  
  63.         if (CurrentPos[2] > 0.0) {
  64.             IGLineTo2D(NewPos[0], NewPos[1]);
  65.         }
  66.         else {
  67.             IGLineTo2D(CurrentPos[0], CurrentPos[1]);
  68.             IGMoveTo2D(NewPos[0], NewPos[1]);
  69.         }
  70.         }
  71.         else {
  72.         if (CurrentPos[2] < 0.0) {
  73.             IGLineTo2D(MidPos[0], MidPos[1]);
  74.         }
  75.         else {
  76.             IGMoveTo2D(NewPos[0], NewPos[1]);
  77.             IGLineTo2D(MidPos[0], MidPos[1]);
  78.         }
  79.  
  80.         IGSetColorIntensity(TRUE);
  81.  
  82.         if (CurrentPos[2] < 0.0) {
  83.             IGLineTo2D(NewPos[0], NewPos[1]);
  84.         }
  85.         else {
  86.             IGLineTo2D(CurrentPos[0], CurrentPos[1]);
  87.             IGMoveTo2D(NewPos[0], NewPos[1]);
  88.         }
  89.         }
  90.     }
  91.     }
  92.     else {
  93.     IGLineTo2D(NewPos[0], NewPos[1]);
  94.     }
  95.  
  96.     GEN_COPY(CurrentPos, NewPos, 3 * sizeof(RealType));
  97. }
  98.